#include "slepbase.h"
#include "cslep.h"

void testRunMCLeastR(){
	int i;
	OPTS opts;
	slep_matrix *A, *Y;
	slep_vector *funVal, *LValue;
	slep_matrix *X;
	double rho;
	stopWatch timer;

	A = slepAllocDenseMatrix(100,100);
	X = slepAllocDenseMatrix(100,10);
	Y = slepAllocDenseMatrix(100,10);
	funVal = slepAllocDenseVector(100);
	LValue = slepAllocDenseVector(100);

	slep_randn(A->data.mtrx,100*100,0.,1.);
	slep_randn(X->data.mtrx,100*10,0.,1.); // its xOrin here..
	slep_randn(Y->data.mtrx,100*10,0.,1.); 
	slep_dgemm(SlepNoTranspose,SlepNoTranspose,1.0,A,X,0.01,Y);

	opts.lFlag=0;
	opts.mFlag=0;
	opts.nFlag=0;
	opts.rFlag=1;

	opts.rsL2=0;
	opts.maxIter=100;

	slepWriteDenseMatrix("A-mclr.slm",A);
	slepWriteDenseMatrix("Y-mclr.slm",Y);

	opts.init = 2;
	opts.tFlag=5;
	opts.maxIter = 100;
	opts.REGISTER = SlepOPT_maxIter | SlepOPT_rsL2 | SlepOPT_q;

	opts.rsL2 = 0.0;
	opts.rFlag = 1;
	rho=0.5;

	opts.mFlag=0;
	opts.lFlag=0;
	startTimer(&timer);
	mcLeastR(A,Y,rho,&opts,X,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));
	slepWriteDenseMatrix("x-mclr-1.slm",X);
	slepVerboseWriteDenseVector("f-mclr-1.slv",funVal);
	slepVerboseWriteDenseVector("L-mclr-1.slv",LValue);

	opts.mFlag=1;
	slep_zerov(X);
	startTimer(&timer);
	mcLeastR(A,Y,rho,&opts,X,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));
	slepWriteDenseMatrix("x-mclr-2.slm",X);
	slepVerboseWriteDenseVector("f-mclr-2.slv",funVal);
	slepVerboseWriteDenseVector("L-mclr-2.slv",LValue);

	opts.lFlag=1;
	opts.mFlag=1;
	slep_zerov(X);
	startTimer(&timer);
	mcLeastR(A,Y,rho,&opts,X,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));
	slepWriteDenseMatrix("x-mclr-3.slm",X);
	slepVerboseWriteDenseVector("f-mclr-3.slv",funVal);
	slepVerboseWriteDenseVector("L-mclr-3.slv",LValue);
}